//
//  HWbiaoqiankongzhiViewController.m
//  HWanGame
//
//  Created by 陈道斌 on 2020/11/23.
//  Copyright © 2020 Chendaobin. All rights reserved.
//

#import "HWbiaoqiankongzhiViewController.h"
#import "HWGameListModel.h"

#import "HWOnlinegameTableCell.h"
#import "HWHomezhongyaodeCell.h"
#import <Masonry/Masonry.h>
@interface HWbiaoqiankongzhiViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(strong,nonatomic) UITableView *otherTableVie;
@property(strong,nonatomic) NSMutableArray *dataMuArr;

@property(strong,nonatomic) NSString *p; //分页
@property(strong,nonatomic) NSString *max_p; // 最大分页
@end

@implementation HWbiaoqiankongzhiViewController

- (UITableView *)otherTableVie {
    
    if (_otherTableVie == nil) {
        _otherTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 0,kScreenW, kScreenH) style:UITableViewStylePlain];
        _otherTableVie.delegate = self;
        _otherTableVie.dataSource = self;
        _otherTableVie.tag = 100;
     //   _otherTableVie.hidden = YES;
        _otherTableVie.estimatedRowHeight = 0;
        _otherTableVie.estimatedSectionFooterHeight = 0;
        _otherTableVie.estimatedSectionHeaderHeight = 0;
        _otherTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        _otherTableVie.backgroundColor = [UIColor whiteColor];
        
        
    }
    
    return  _otherTableVie;
    
    
}




- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor redColor];
//    self.otherTableVie.contentInsetAdjustmentBehavior= UIScrollViewContentInsetAdjustmentNever;
    [self.view addSubview:self.otherTableVie];
    [self.otherTableVie mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.mas_equalTo(0);
        
    }];
    self.navigationItem.title = self.dataDic[@"name"]; 
    [self addrefreshControl];
    
}



- (void)addrefreshControl {
    

    self.otherTableVie.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(underRefresh)];
    
    [self.otherTableVie.mj_header beginRefreshing];
    
    self.otherTableVie.mj_footer = [MJRefreshAutoFooter footerWithRefreshingTarget:self refreshingAction:@selector(onRefresh)];
    
    
    
}



//下拉刷新
- (void)underRefresh {
    DLog(@"精选");
    
    
  //   HWFeiLeimodel *model =  self.selectedModel;
    self.p  = @"1";
    
    self.dataMuArr = [[NSMutableArray alloc]init];
    
   
    
    NSDictionary *parametes = @{
                                @"ct" :  @"app",
                                @"ac" : @"fenlei_game",
                                @"type": self.dataDic[@"id"],
                                @"p"  : self.p,
                                @"ios" : @"1"
                                };
    
    
  
    
    [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
        
        
        NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
       
   
        [self.otherTableVie.mj_header endRefreshing];
        [self.otherTableVie.mj_footer endRefreshing];
        
        
        if ([codeStr intValue] == 1) {
          //  [MBProgressHUD  showError:@"加载成功"];
                NSArray *arr = response[@"data"];
          
                self.dataMuArr = [HWGameListModel mj_objectArrayWithKeyValuesArray:arr];
                
                self.p = [NSString stringWithFormat:@"%@",response[@"p"]];
                
                self.max_p = [NSString stringWithFormat:@"%@",response[@"max_p"]];
                
              
                [self.otherTableVie reloadData];
                


          
            
            
        } else {
            
            self.dataMuArr = [[NSMutableArray alloc]init];
            
            [MBProgressHUD showError:response[@"message"]];
            
            
            
            [self.otherTableVie reloadData];
            
        }
        NSLog(@"%@",response);
        
        
    } failure:^(NSString *error) {
        
      
        [self.otherTableVie.mj_header endRefreshing];
        [self.otherTableVie.mj_footer endRefreshing];
        
        
        
    }];
    
    
    
    
    
    
    
}
//  上拉刷新

- (void)onRefresh {
    
    DLog(@"精选");
    
    
//     HWFeiLeimodel *model =  self.selectedModel;
    
    
    NSDictionary *parametes = @{
                                @"ct" :  @"app",
                                @"ac" : @"fenlei_game",
                                @"type":self.dataDic[@"id"] ,
                                @"p"  : self.p,
                                @"ios" : @"1"
                                };
    
    
    
    
    [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
        
        
        NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
       
        [self.otherTableVie.mj_header endRefreshing];
        [self.otherTableVie.mj_footer endRefreshing];
        
        if ([codeStr intValue] == 1) {
          //  [MBProgressHUD  showError:@"加载成功"];
            NSArray *arr = response[@"data"];
            if (arr.count > 0) {
                
                
              NSMutableArray  *muArr  = [HWGameListModel mj_objectArrayWithKeyValuesArray:arr];
                
                for (int i = 0; i < muArr.count; i++) {
                    
                    [self.dataMuArr addObject:muArr[i]];
                    
                }
                
                self.p = [NSString stringWithFormat:@"%@",response[@"p"]];
                
                self.max_p = [NSString stringWithFormat:@"%@",response[@"max_p"]];
            
              
                [self.otherTableVie reloadData];
                
            }
            
            
            
            
        } else {
            
            
            
        }
        NSLog(@"%@",response);
        
        
    } failure:^(NSString *error) {
        
        
        [self.otherTableVie.mj_header endRefreshing];
        [self.otherTableVie.mj_footer endRefreshing];
        
    }];
    
    
    
}





- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    
    
      return   self.dataMuArr.count;
    if (tableView.tag == 100) {
         return   self.dataMuArr.count;
    }
  
    
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        

      static NSString *cellID = @"cellID1";
         
         HWHomezhongyaodeCell  *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
         
         
         if (!cell) {
             cell = [[NSBundle mainBundle]loadNibNamed:@"HWHomezhongyaodeCell" owner:nil options:nil].firstObject;
             
         }
          HWGameListModel  *model = self.dataMuArr[indexPath.row];
         cell.youxiModel = model;
         cell.xiantiaoView.hidden = YES;
      
       cell.newbeijingiamgeView.hidden = YES;
       cell.beijingshituView.backgroundColor = [UIColor whiteColor];
                    
       cell.jianjutupian.constant = 0;
      cell.topjianju.constant = 31;
      
      cell.contentView.backgroundColor  = RGB(255, 255, 255);
      
      return  cell;
      
         
        
   
    
  
    
}







- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    if (tableView.tag == 100 ) {
        
        return 75;
    }
    return  56;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    DLog(@"1234");
    
    
    if (tableView.tag == 100 ) {
        
        
        NSLog(@"daying");
        
       HWGameListModel *model = self.dataMuArr[indexPath.row];
       HWGameDetailController *gameDetails = [[HWGameDetailController alloc]init];
       gameDetails.gameId = model.id;
       
       [self.navigationController pushViewController:gameDetails animated:YES];
       
        
    } else {
        
        
    
        
        
        
    }
        
   
   
    
    
    
    
}











@end
